﻿using B.S.BaseData.Api.Write.Applicantion.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.GoodsCommandHandler
{
    public class GoodsInfoUpdateCommandHandler : IRequestHandler<GoodsInfoUpdateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<GoodsInfo> _goodsbaseRepository;
        public GoodsInfoUpdateCommandHandler(IBaseRepository<GoodsInfo> goodsbaseRepository)
        {
            _goodsbaseRepository = goodsbaseRepository;
        }
        public async Task<APIResult<int>> Handle(GoodsInfoUpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var model =await _goodsbaseRepository.GetValues(x=>x.Id==request.Id);
            model.GoodsName = request.GoodsName;
            model.GoodsProductionbatches = request.GoodsProductionbatches;
            model.GoodsShelflife = request.GoodsShelflife;
            model.GoodsProductionLicense = request.GoodsProductionLicense;
            model.GoodsConpany = request.GoodsConpany;
            model.GoodsImg = request.GoodsImg;
            var res = await _goodsbaseRepository.UpdateAsync(model);
            result.Code = ApiEnum.Success;
            result.Msg = "商品信息修改成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
